<template>
  <div>
    <div class="header_min">
      <div class="wrap header_min_box">
        <div @click="GoIndex()" class="fl logo">
          <img src="@/assets/image/logo_shape@2x.png" alt />
          联众医药
        </div>
        <div class="index_search">
          <input type="text" v-model="searchTxt" maxlength="12" />
          <button v-if="searchState == 0" @click="Gosearch()">搜索</button>
          <button v-if="searchState == 1" @click="search_Send()">搜索</button>
        </div>
        <button @click="GoAllGoods()" class="all_goods">全部商品</button>
      </div>
      <div></div>
    </div>
  </div>
</template>

<script>
// import AMap from "AMap"; // 引入高德地图
// import {getShoplist} from '@/request/public'

import { search } from "@/request/index"; // 搜索
export default {
  data() {
    return {
      searchState: 0,
      searchTxt: ""
    };
  },
  created() {
    let path = this.$route.path;
    this.searchTxt = this.$route.query.search;
    if (path.indexOf("search") != -1 || path.indexOf("allGoods") != -1) {
      this.searchState = 1;
      if (this.searchTxt != undefined) {
        this.search_Send();
      }
    }
  },
  mounted() {},
  methods: {
    GoAllGoods(){
       this.$router.push({ path: "/allGoods" });
    },
    GoIndex() {
      this.$router.replace({ path: "/" });
    },
    Gosearch() {
      this.$router.push({ path: "/search?search=" + this.searchTxt });
    },
    // 搜索
    search_Send() {
      search({
        keyword: this.searchTxt
      }).then(res => {
        let datas = res.data;
        if (datas.disease_info !== null) {
          let data = {};
          data.state = 1;
          data.data = datas;
          data.title = this.searchTxt;
          this.$emit("search", data);
        } else {
          this.$message.error("没有找到您输入的关键词相关的内容");
          let data = {};
          data.state = 0;
          data.title = this.searchTxt;
          this.$emit("search", data);
        }
      });
    }
  }
};
</script>
<style lang="less" scoped>
.index_search {
  width: 796px;
  height: 48px;
  border: 2px solid #38eec1;
  position: absolute;
  left: 52%;
  top: 50%;
  transform: translate(-50%, -50%);
  input {
    margin-top: 2px;
    margin-left: 10px;
    height: 40px;
    width: 600px;
  }
  button {
    height: 100%;
    width: 152px;
    font-size: 20px;
    float: right;
  }
}
.all_goods {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translate(0, -50%);
  width: 152px;
  height: 48px;
  background: #fdb65a;
  font-size: 20px;
}
</style>
